﻿using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SeleniumExtension.Features
{
    public class TakeScreenshot
    {
        public static void Snap(IWebDriver driver, string fileName)
        {
            ITakesScreenshot screenShotDriver = driver as ITakesScreenshot;
            Screenshot screenShot = screenShotDriver.GetScreenshot();
            var parentFolder = AppDomain.CurrentDomain.BaseDirectory;
            var folder = Path.Combine(parentFolder, DateTime.Now.ToString("dd-MM-yyyy"));
            if (!System.IO.Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            fileName = string.Format("{0}\\{1}", folder, fileName);
            screenShot.SaveAsFile(fileName, ImageFormat.Png);
        }
    }
}
